<template>
  <div v-if="content" class="custom-swiper mar-b-10 mar-t-23">
    <div class="swiper-con">
      <el-carousel :height="swiperHeight + 'px'" arrow="never" class="carousel" indicator-position="none">
        <el-carousel-item v-for="(itemSwiper, indexSwiper) in content.guideList" :key="indexSwiper">
          <img :src="itemSwiper.imgUrl" alt="" class="swiper-img cursor-p" @click="handleJumpPage(itemSwiper)">
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>

<script lang="ts">
  import {
    defineComponent,
    ref,
    onMounted
  } from 'vue'
  import {
    useRouter
  } from 'vue-router'
  import {
    jumpPage
  } from '@/utils/jumpPageUtils'
  export default defineComponent({
    name: 'CustomSwiperFirst',
    props: {
      content: {
        type: Object,
        default: () => ({})
        // type: Array,
        // default: () => []
      }
    },
    setup(props) {
      const router = useRouter()
      const swiperHeight = ref(< number > 0)
      onMounted(() => {
        // 获取第一张图片的原图尺寸大小
        const img = new Image()
        img.src = props.content.guideList[0].imgUrl
        img.onload = function() {
          // 盒子跨度为1400
          swiperHeight.value = (document.documentElement.clientWidth * img.height) / img.width
        }
      })

      const handleJumpPage = (item: any) => {
        jumpPage(router, item.hasLink, item.linkTarget, item.linkType, item.linkParams, item.newPage)
      }

      return {
        swiperHeight,
        handleJumpPage
      }
    }
  })
</script>

<style lang="scss" scoped>
  $darkBlue: #182245;

  .custom-swiper {
    ::v-deep(.carousel) {
      &.el-carousel {
        --el-carousel-indicator-width: 10px;
        --el-carousel-indicator-height: 10px;

        .el-carousel__button {
          border-radius: 50px;
          // background-color: #000;
        }
      }
    }

    .el-carousel__item {
      text-align: center;
    }

    .swiper-img {
      width: 100%;
      height: 100%;
    }
  }
</style>
